package com.xca.znb.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.xca.znb.R;
import com.xca.znb.contact.PublishContact;
import com.xca.znb.presenter.PublishPresenter;

public class PublishFragment extends Fragment implements View.OnClickListener , PublishContact {
    private View publish_fragment ;
    private PublishPresenter publishPresenter ;
    private LinearLayout PublishGoods , PublishProcurement ;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (publish_fragment == null){
            publish_fragment = inflater.inflate(R.layout.publish_paper , container , false);
        }
        publishPresenter  = new PublishPresenter(this);
        PublishGoods = publish_fragment.findViewById(R.id.publish_goods);
        PublishProcurement = publish_fragment.findViewById(R.id.publish_procurement);

        onToPublishGoodsBtnClick();
        onToPublishProcurementBtnClick();

        return publish_fragment ;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.publish_goods){
            Intent intent = new Intent(getActivity() , AddGoodsActivity.class);
            startActivity(intent);
        } else if (v.getId() == R.id.publish_procurement) {
            Intent intent = new Intent(getActivity() , ProcurementDynamicActivity.class);
            startActivity(intent);
        }
    }

    @Override
    public void onToPublishGoodsBtnClick() {
        PublishGoods.setOnClickListener(this);
    }

    @Override
    public void onToPublishProcurementBtnClick() {
        PublishProcurement.setOnClickListener(this);
    }
}
